package ttOrder.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ttOrder.model.Foodtype;

@Repository
public class FoodTypeDAOImpl extends BaseHibernateDAO<Foodtype> implements IFoodTypeDAO {
	@Autowired
	private SessionFactory sessionFactory;

	public Session getSession() {
		return this.sessionFactory.getCurrentSession();
	}
	@Override
	public List<Foodtype> findAllFoodtype() {

		Session session = getSession();
		String hql = "from Foodtype";
		@SuppressWarnings("unchecked")
		List<Foodtype> foodtype = session.createQuery(hql).list();
		return foodtype;
	}

	@Override
	public Foodtype getFoodtypeById(Integer id) {
		Session session = getSession();
		return (Foodtype) session.get(Foodtype.class, id);
	}

	@Override
	public void createFoodtype(Foodtype foodtype) throws Exception {
		this.save(foodtype);
	}

	@Override
	public void editFoodtype(Foodtype foodtype) throws Exception {
		this.update(foodtype);
	}

	@Override
	public Integer deleteFoodtype(Integer id) throws Exception {
		Session session = getSession();
		Foodtype foodtype = (Foodtype) session.get(Foodtype.class, id);

		if (foodtype != null) {
			session.delete(foodtype);

		}
		return null;
	}
}
